<?php 
namespace app\common\model;
class Stat extends Common{
	public function getTypeAttr($value, $data){
		$arr = [1=>'api接口',2=>'客户统计',3=>'商品统计'];
		return $data['typeid'] ? $arr[$data['typeid']] : '未知';
	}
	public function addStat($contentid,$salenums,$totalprice,$typeid){
		$nowday = date("Y-m-d");
		$data = array(
			'typeid' => $typeid,
			'contentid' => $contentid,
			'addday' => $nowday,
		);
		$iscount = $this->where($data)->count();
		if($iscount){
			$this->where($data)->setInc("salenums",$salenums);
			$id = $this->where($data)->setInc("totalprice",$totalprice);
		}
		else{
			$data['salenums'] = $nums;
			$data['totalprice'] = $totalprice;
			$id = $this->save($data);
		}
		return $id;
	}
}